Skip to content

fix: avoid mime_content_type warning on wrapped streams#592

Open
olddude2 wants to merge 1 commit into
nextcloud:mainfrom
olddude2:fix/mime-content-type-stream-cast-warning
Open

fix: avoid mime_content_type warning on wrapped streams#592
olddude2 wants to merge 1 commit into
nextcloud:mainfrom
olddude2:fix/mime-content-type-stream-cast-warning

Conversation

@olddude2

Copy link
Copy Markdown

mime_content_type() requires stream_cast() support to operate on a stream resource directly. Streams returned by File::fopen() can be wrapped in Icewind\Streams\CallbackWrapper, which does not implement stream_cast(), causing a PHP warning to be logged on every preview/output-file request even though the mime type is still detected correctly.

This drains the stream into a temporary file first, then calls mime_content_type() against the file path instead. No behavior change; only removes log noise.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

mime_content_type() requires stream_cast() support to operate on a
stream resource directly. Streams returned by File::fopen() can be
wrapped in Icewind\Streams\CallbackWrapper, which does not implement
stream_cast(), causing a PHP warning to be logged on every
preview/output-file request even though the mime type is still
detected correctly.

This drains the stream into a temporary file first, then calls
mime_content_type() against the file path instead. No behavior change;
only removes log noise.

Signed-off-by: Simon Holzman <simon.holzman@verizon.net>
@olddude2

olddude2 commented Jul 9, 2026

Copy link
Copy Markdown
Author

The PHPUnit / php8.2-sqlite-master failure appears to be a pre-existing
issue — the job fails during Nextcloud installation before any tests run,
with "This version of Nextcloud requires at least PHP 8.3" (PHP 8.2.31 is
being used against master). The php8.2-sqlite-stable33 job passes cleanly.

Happy to rebase or make any adjustments if needed — just let me know.

public function getOutputFilePreviewFile(string $userId, int $taskId, int $fileId, ?int $x = 100, ?int $y = 100): ?array {
$taskOutputFile = $this->getTaskOutputFile($userId, $taskId, $fileId);
$realMime = mime_content_type($taskOutputFile->fopen('rb'));
$realMime = $this->detectMimeType($taskOutputFile->fopen('rb'));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$realMime = $this->detectMimeType($taskOutputFile->fopen('rb'));
$head = fread($stream, 4096);
if (is_resource($stream)) {
fclose($stream);
}
$realMime = new \finfo(FILEINFO_MIME_TYPE)->buffer($head);

Thank you for your contribution! Unfortunately we cannot merge this as copying the whole file to disk has a too high performance impact especially for big files. An easier fix would be to not use mime_content_type as shown above, would you be up for testing and validating if that works without any issues?

@janepie

janepie commented Jul 13, 2026

Copy link
Copy Markdown
Member

fixes #591

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mime_content_type() logs a stream_cast warning on every Assistant preview/output-file request

2 participants